﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HCFramework.API.LINQ;

namespace HCFramework.Product.Ajax
{
    public partial class GetListProductName : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string keyword = M.UrlQuery.q;
            keyword = keyword.ToLower().Replace(" ", "");
            HCDataContext db = new HCDataContext();
            var result = from a in db.Products
                         where a.ProductName.ToLower().Replace(" ", "").Contains(keyword)
                            && a.IsActive
                         select a;

            if (M.UrlQuery.categoryID.HasValue)
            {
                result = from r in result
                         where r.CategoryID == M.UrlQuery.categoryID.Value
                         select r;
            }

            result = from r in result
                     orderby r.ProductName
                     select r;

            List<API.LINQ.Product> listProduct = result.Take(M.UrlQuery.limit.Value).ToList();
            litMain.Text = String.Join("\n", listProduct.Select(ik => ik.ProductName));
        }
    }
}